﻿using System.Drawing;
using System.Linq;
using System.Resources;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;

namespace PropertyManagement.Client.WinFormClient.Forms.Utilies
{
    public class ResourceUtil
    {
        private static ResourceManager rm;

        static ResourceUtil()
        {
            rm = new ResourceManager("Hotal.Client.WinForm.Forms.PngResource", typeof(ResourceUtil).Assembly);
        }

        /// <summary>
        /// Get image from resource
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static Image GetImage(string str)
        {
            return (Image)rm.GetObject(str);
        }

        /// <summary>
        /// 校验权限
        /// </summary>
        /// <param name="toolBar"></param>
        /// <param name="form"></param>
        public static void HandleAuthority(BarManager toolBar, XtraForm form)
        {
            if (ConfigCache.UserInfo.Actions == "ALL")
                return;
            foreach (var item in toolBar.Items.OfType<BarButtonItem>().Where(item => item.Tag as string != "N"))
            {
                item.Enabled = ConfigCache.UserInfo.Actions.Contains(form.Text + "." + item.Caption);
            }
        }
    }
}
